package GUI.Productos;

import java.rmi.RemoteException;

import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.SWT;
import org.eclipse.wb.swt.SWTResourceManager;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

import article.entities.ArticleVO;
import service.ServiceFacade;
import service.article.exceptions.ProxyException;
import service.article.interfaces.ArticleProxyMgt;
import GUI.Administracion.Exceptions.ExcepcionesMenuVentas;

public class MenuProductos extends Dialog {

	protected Object result;
	protected Shell shell;

	/**
	 * Create the dialog.
	 * @param parent
	 * @param style
	 */
	public MenuProductos(Shell parent, int style) {
		super(parent, style);
		setText("MenuProductos");
	}

	/**
	 * Open the dialog.
	 * @return the result
	 */
	public Object open() {
		createContents();
		shell.open();
		shell.layout();
		Display display = getParent().getDisplay();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		return result;
	}

	/**
	 * Create contents of the dialog.
	 */
	private void createContents() {
		shell = new Shell(getParent(), getStyle());
		shell.setSize(450, 300);
		shell.setText(getText());
		
		Label label = new Label(shell, SWT.NONE);
		label.setText("ELIJA LA OPCION DESEADA");
		label.setFont(SWTResourceManager.getFont("Lucida Grande", 13, SWT.NORMAL));
		label.setAlignment(SWT.CENTER);
		label.setBounds(139, 26, 176, 17);
		
		Button button = new Button(shell, SWT.NONE);
		button.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				AddProductos a = new AddProductos(shell, shell.getStyle(), null,null);
				shell.setVisible(false);
				try {
					a.open();
				} catch (RemoteException e1) {
					ExcepcionesMenuVentas ventana = new ExcepcionesMenuVentas (shell, shell.getStyle(), "Error de Conexion con el Servidor");
					ventana.open();
					shell.dispose();
					e1.printStackTrace();
				} catch (ProxyException e1) {
					ExcepcionesMenuVentas ventana = new ExcepcionesMenuVentas (shell, shell.getStyle(), "Error de Conexion con el Servidor");
					ventana.open();
					shell.dispose();
					e1.printStackTrace();
				}
			}
		});
		button.setText("Agregar Nuevo Producto");
		button.setBounds(131, 60, 191, 28);
		
		Button button_1 = new Button(shell, SWT.NONE);
		button_1.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				ArticleProxyMgt uso = ServiceFacade.getInstance().getArticleProxyMgt();
				ArticleVO[] arts;
				try {
					arts = uso.getArticles();
					verProd ver = new verProd(arts, false);
				//	shell.setVisible(false);
					//ver.open(arts,true);
					
					
				} catch (RemoteException e1) {
					ExcepcionesMenuVentas ventana = new ExcepcionesMenuVentas (shell, shell.getStyle(), "Error de Conexion con el Servidor");
					ventana.open();
					shell.dispose();
					e1.printStackTrace();
				} catch (ProxyException e1) {
					ExcepcionesMenuVentas ventana = new ExcepcionesMenuVentas (shell, shell.getStyle(), "Error de Conexion con el Servidor");
					ventana.open();
					shell.dispose();
					e1.printStackTrace();
				}
			
				
				
			}
		});
		button_1.setText("Ver Productos del Menu");
		button_1.setBounds(131, 105, 191, 28);
		
		Button button_2 = new Button(shell, SWT.NONE);
		button_2.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				ArticleProxyMgt uso = ServiceFacade.getInstance().getArticleProxyMgt();
				ArticleVO[] arts;
				try {
					arts = uso.getArticles();
					verProd ver = new verProd(arts, true);
					
					
				} catch (RemoteException e1) {
					ExcepcionesMenuVentas ventana = new ExcepcionesMenuVentas (shell, shell.getStyle(), "Error de Conexion con el Servidor");
					ventana.open();
					shell.dispose();
					e1.printStackTrace();
				} catch (ProxyException e1) {
					ExcepcionesMenuVentas ventana = new ExcepcionesMenuVentas (shell, shell.getStyle(), "Error de Conexion con el Servidor");
					ventana.open();
					shell.dispose();
					e1.printStackTrace();
				}
			}
		});
		button_2.setText("Modificar/Eliminar Productos ");
		button_2.setBounds(131, 150, 191, 28);
		
		Button button_3 = new Button(shell, SWT.NONE);
		button_3.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				NuevoCombo nuevo = new NuevoCombo (shell, shell.getStyle());
				nuevo.open();
			}
		});
		button_3.setText("Agregar Nuevo Combo");
		button_3.setBounds(131, 195, 191, 28);
		
		Button button_4 = new Button(shell, SWT.NONE);
		button_4.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				BajaCombo b = new BajaCombo (shell, shell.getStyle());
				b.open();
			}
		});
		button_4.setText("Borrar Combo del Menu");
		button_4.setBounds(139, 240, 176, 28);

	}

}
